//
//  YQLongPressBtn.swift
//  yq微信
//
//  Created by 杨庆 on 2018/1/12.
//  Copyright © 2018年 yq. All rights reserved.
//

import UIKit


/// 自定义(包含长按手势)按钮
class YQLongPressBtn: UIButton {
    // 声明闭包
    typealias YQLongPressBlock = (YQLongPressBtn)->()
    // 声明属性
    var longPressBlock : YQLongPressBlock?

    // 回调函数
    func longPressCallBack(longPressCallBackBlock:@escaping YQLongPressBlock) {
        self.longPressBlock = longPressCallBackBlock
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        // 添加长按手势
        let gestureRegr:UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self , action: #selector(longPress))
        self.addGestureRecognizer(gestureRegr)
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // 长按手势 -- 回调
    func longPress(){
        if (self.longPressBlock != nil) {
            longPressBlock!(self)
        }
    }
    
    
    
}
